//
//  CellForSearchTrips.m
//  ProjectA
//
//  Created by dllo on 16/2/28.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "CellForSearchTrips.h"
#import "ModelForSearchTrips.h"
#import <UIImageView+WebCache.h>
#import "AppMacro.h"
@interface CellForSearchTrips ()

@property (nonatomic, strong) UILabel *count;
@property (nonatomic, strong) UILabel *waypoints;   //足迹数
@property (nonatomic, strong) UILabel *label;   //彩块
@property (nonatomic, strong) UILabel *name;    //标题
@property (nonatomic, strong) UIImageView *imageViewForBg;  //背景照片
@end

@implementation CellForSearchTrips
- (void)dealloc {
    
    [_count release];
    [_waypoints release];
    [_name release];
    [_imageViewForBg release];
    
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imageViewForBg = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageViewForBg];
        [_imageViewForBg release];
    
        self.name = [[UILabel alloc] init];
        [self.imageViewForBg addSubview:self.name];
        [_name release];
        
        self.label = [[UILabel alloc] init];
        [self.imageViewForBg addSubview:self.label];
        [_label release];
        
     
        self.waypoints = [[UILabel alloc] init];
        [self.imageViewForBg addSubview:self.waypoints];
        [_waypoints release];
        
        self.count = [[UILabel alloc] init];
        [self.imageViewForBg addSubview:self.count];
        [_count release];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    self.imageViewForBg.frame = CGRectMake(10, 5, self.frame.size.width - 20, self.frame.size.height - 10);
    self.imageViewForBg.backgroundColor = [UIColor clearColor];
    
    self.name.frame = CGRectMake(15, 5, self.contentView.frame.size.width - 50, 30);
    
    self.label.frame = CGRectMake(15, 30 + 7, 3, 15);
    self.label.layer.cornerRadius = 3;
    self.label.layer.masksToBounds = YES;

 
    self.waypoints.frame = CGRectMake(15 + 3 + 5 + 5, 30 + 5, self.contentView.frame.size.width - 50, 20);
    self.waypoints.font = [UIFont systemFontOfSize:13];
    
    self.count.frame = CGRectMake(15, self.contentView.frame.size.height - 35, self.contentView.frame.size.width - 50, 20);
    self.count.font = [UIFont systemFontOfSize:12];
    
    if (ISNIGHT) {
        self.name.textColor = L_COLOR_WHITE;
        self.label.backgroundColor = [UIColor whiteColor];
        self.waypoints.textColor = L_COLOR_WHITE;
        self.count.textColor = L_COLOR_WHITE;
    } else {
        self.name.textColor = L_COLOR_WHITE;
        self.label.backgroundColor = RGBA(68, 177, 207, 1);
        self.waypoints.textColor = L_COLOR_WHITE;
        self.count.textColor = L_COLOR_WHITE;
    }
}
- (void)passData:(ModelForSearchTrips *)model withSearch:(NSString *)search {
    
    NSString *w = [NSString stringWithFormat:@"w/%ld", (NSInteger)self.frame.size.width];
    
    NSString *h = @"h/100";
    
    NSString *temp = [model.cover_image_1600 stringByReplacingOccurrencesOfString:@"w/640" withString:w];
    
    NSString *str = [temp stringByReplacingOccurrencesOfString:@"h/480" withString:h];
    

    [self.imageViewForBg sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"iconfont-zhanweitu"]];
    
    self.name.text = model.name;

    NSString *waypoints = [NSString stringWithFormat:@"足迹 %@", model.waypoints];
    self.waypoints.text = waypoints;
    
    NSString *url = [NSString stringWithFormat:@"%@ 浏览 / %@ 喜欢 / %@ 评论", model.view_count, model.liked_count, model.total_comments_count];
    self.count.text = url;

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
